package org.git.movie.videojiexi.common.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class VideoHelper {
    public static String decodeHttpUrl(String url) {
        int start = url.indexOf("http");
        int end = url.lastIndexOf("/");
        String decodeurl = url.substring(start, end);
        return decodeurl;
    }
    //写一些共有的静态方法
    public static String buidFileName (String  userAgent, String name) throws UnsupportedEncodingException {
        String fileName = name;
        //获得浏览器信息并转换为大写
        String agent = userAgent.toUpperCase();
        //IE浏览器和Edge浏览器
        if (agent.indexOf("MSIE") > 0 || (agent.indexOf("GECKO") > 0 && agent.indexOf("RV:11") > 0)) {
            fileName = URLEncoder.encode(fileName, "UTF-8");
        } else {  //其他浏览器
            fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
        }
        return fileName;
    }
    public static Map<String,String> parse2Map(String queryMapString){
        Map<String,String> rep = new HashMap<>();

        String[] paramArray = queryMapString.split("&");

        String[] itemArray = null;
        for(String param :paramArray){
            itemArray =  param.split("=");
            if(itemArray.length == 3){
                rep.put(itemArray[0],itemArray[1]+"="+itemArray[2]);
            } else if(itemArray.length == 2)  {
                rep.put(itemArray[0],itemArray[1]);
            }else   {
                rep.put(itemArray[0],null);
            }
        }
        return rep;
    }
}
